package com.wms.service.impl;

import com.wms.dao.UserDao;
import com.wms.model.User;
import com.wms.service.UserService;
import com.wms.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @author This
 * @version 1.0
 * @date 2019/7/10 13:45
 */
@Service
@Transactional
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {

    @Autowired
    private UserDao dao;

    @Override
    public boolean add(User user) {
        List<User> list = dao.findByCondition(" username=? ", user.getUsername());
        if (CommonUtils.isEmpty(list)) {
            dao.save(user);
            return true;
        }
        return false;
    }

    @Override
    public void delete(User user) {

    }

    @Override
    public void edit(User user) {

    }

    @Override
    public User find(Serializable id) {
        return null;
    }

    @Override
    public void deleteAll(String ids) {

    }

    @Override
    public boolean hasUser() {
        return dao.hasUser();
    }

    @Override
    public int count(String condition) {
        return (dao.count(new User(),condition)).intValue();
    }

    /**
     * 根据用户名和密码查询
     *
     * @param username 用户名
     * @param password 密码
     * @return User
     */
    @Override
    public User getOne(String username, String password) {
        return dao.findOne(username, password);
    }

    @Override
    public int executeUpdate(Map<Object, Object> param) {
        return 0;
    }
}
